package com.cxw.healthserver.service

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.cxw.healthserver.bean.Doctor
import com.cxw.healthserver.entity.Token
import com.cxw.healthserver.entity.User
import com.cxw.healthserver.mapper.UserMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class UserService {
    @Autowired
    private lateinit var userMapper: UserMapper

    fun getUserByUsernameAndPassword(username: String, password: String): User? {
        return userMapper.selectOne(QueryWrapper<User>().eq("username", username).eq("password", password))
    }
    fun getUserByUsername(username: String): User? {
        return userMapper.selectOne(QueryWrapper<User>().eq("username", username))
    }

    fun getUserByUserid(userid:String): User? {
        return userMapper.selectOne(QueryWrapper<User>().eq("id", userid))
    }

    fun getDoctors():MutableList<Doctor>{
        val selectList = userMapper.selectList(QueryWrapper())
        return selectList.map{
            Doctor(it.id,it.username,it.realname)
        }.toMutableList()
    }
}